// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
const CDN_PATH = 'https://yunbiz.wps.cn/';
const workboxPlugin = require('workbox-webpack-plugin');
const { compile } = require('vue-template-compiler');
/* const { createTransformerVueJsxProps } = require('./ts-transform-vue-jsx-props'); */
function resolve(dir) {
  return path.join(__dirname, dir);
}
const emptyBaseNodeAttr = {
  name: '',
  value: '',
};
module.exports = {
  publicPath: process.env.VUE_APP_BUILD === 'production' ? `${CDN_PATH}/workbox/` : '',
  /* ... other settings */
  transpileDependencies: ['vuex-module-decorators'],
  configureWebpack: {
    resolve: {
      alias: {
        /* vue$: 'vue/dist/vue.esm.js', */
        '@': resolve('src'),
        '@todo': resolve('src/components-todo'),
        '@const': resolve('src/const'),
        '@views': resolve('src/views'),
        '@components': resolve('src/components'),
        '@material': resolve('src/views/material'),
        '@constant': resolve('src/constant'),
        '@services': resolve('src/services'),
        '@common': resolve('src/common'),
        '@utils': resolve('src/utils'),
        '@model': resolve('src/model'),
        '@store': resolve('src/store'),
      },
    },
    plugins: [
      /* new VueLoaderPlugin({compiler:}), */
      /*  new workboxPlugin.GenerateSW({
        swDest: 'build.sw.js',
        // workbox-sw.js 部署本地服务器
        // （预加载）忽略某些文件
        exclude: [/index\.html$/],
        mode: 'debugging',
        // 动态更新缓存
        runtimeCaching: [
          {
            urlPattern: /index\.html/,
            handler: 'NetworkFirst',
          },
          {
            urlPattern: /\.(js|css|png|jpg|gif)/,
            handler: 'StaleWhileRevalidate',
          },
        ],
        maximumFileSizeToCacheInBytes: 4 * 1024 * 1024,
      }), */
    ],
  },
  chainWebpack: (config) => {
    config.module
      .rule('tsx')
      .use('ts-loader')
      .loader('ts-loader')
      .tap((options) => {
        // 修改它的选项1sss...
        return {
          ...options,
          transpileOnly: true,
          getCustomTransformers: path.join(__dirname, './webpack.ts-transformers.js'),
        };
      });
    config.module
      .rule('ts')
      .use('ts-loader')
      .loader('ts-loader')
      .tap((options) => {
        // 修改17它的选项...
        return {
          ...options,
          transpileOnly: true,
          getCustomTransformers: path.join(__dirname, './webpack.ts-transformers.js'),
        };
      });
    config.module
      .rule('vue')
      .use('vue-loader')
      .tap((options) => {
        // 修改它的选项...

        const transformCode = {
          transformCode: (el, code) => {
            return code;
          },
          transformNode: (node) => {
            if (node.tag === 'WContainer') {
              node.attrsList.push({
                name: 'title',
                value: 'inject vue',
              });
            }
            return node;
          },
        };
        if (Array.isArray(options.compilerOptions.modules)) {
          options.compilerOptions.modules.push(transformCode);
        } else {
          options.compilerOptions.modules = [];
          options.compilerOptions.modules.push(transformCode);
        }
        console.log('optionssssss');
        return options;
      });
  },
  devServer: {
    /* host: 'admin.pic.kso.kingsoft.net', */
    disableHostCheck: true,
    headers: {
      'Access-Control-Allow-Origin': '*',
    },
    /*  https: true,
    port: 443, */
    overlay: {
      warnings: true,
      errors: true,
    },
  },
};
